/*
 * @: saga里采用generator函数来yeild effect对象
 * @version: 1.0
 * @Author: ziwei
 * @Date: 2021-11-01 23:57:34
 * @LastEditors: ziwei
 * @LastEditTime: 2021-11-02 10:35:10
 */

function put(action){
    return {type:"PUT",action}
}

function * gen(){
    yield {type:"PUT",action:{type:"ADD"}}
    yield new Promise((resolve,reject)=>setTimeout(resolve,1000))
    yield {type:"PUT",action:{type:"MINUS"}}
}

function run(gen) {
  let  it = gen();
  function next() {
    let {done,value} = it.next();
    console.log(value);
    if(value instanceof Promise){
      value.then(()=>{
        if(!done){
          next();
        }
      })
    }
    if(!done){
      next();
    }
  }
  next();
}
run(gen)
// saga中co库 自动执行生成器函数 执行生成器返回迭代器

// let {value} = it.next();
// if(value.type === 'PUT'){
//     //派发一个动作value.action store.dispatch(value.action)
// }
// let {value} = it.next();
// if(value.type === 'PUT'){
//     //派发一个动作value.action store.dispatch(value.action)
// }


// let it = gen();
// function next(){
//     let {done,value} = it.next();
//     if(!done){
//         next()
//     }
// }
// next();



